const dataArr = [3, 5, 6, 7, 9, 3, 8, 10, 3];

const newdataArr = [
  {
    value: 3,
    index: 0,
    times: 1, //第几次出现
  },
  {
    value: 5,
    index: 1,
    times: 1,
  },
  {
    value: 6,
    index: 2,
    times: 1,
  },
  {
    value: 7,
    index: 3,
    times: 1,
  },
  {
    value: 9,
    index: 4,
    times: 1,
  },
  {
    value: 3,
    index: 5,
    times: 2,
  },
  {
    value: 8,
    index: 6,
    times: 1,
  },
  {
    value: 10,
    index: 7,
    times: 1,
  },
  {
    value: 3,
    index: 8,
    times: 3,
  },
];

const result = [];
const timesArr = {};
dataArr.forEach((item,index)=>{
    if (result.findIndex((v)=>v.value == item) == -1){
        result.push({
            value:item,
            index:index,
            times: 1
        });
        timesArr[item] = 1;

    } else {
        timesArr[item]++;
        result.push({
            value:item,
            index:index,
            times: timesArr[item] 
        })
    }
})


function validateRuleModel(data) {
    const result = [];
    const timesArr = {};

    data.forEach((item,index)=>{
        if (result.findIndex((v)=>v.value == item) == -1){
            result.push({
                value:item,
                index:index,
                times: 1
            });
            timesArr[item] = 1;
    
        } else {
            timesArr[item]++;
            result.push({
                value:item,
                index:index,
                times: timesArr[item] 
            })
        }
    })

    return result;
}